package ubiqweb.spring3.controller;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import ubiqweb.spring3.model.ChangePassword;

@Component("changePasswordValidator")
public class ChangePasswordValidation {
	public boolean supports(Class<?> klass) {
		return ChangePassword.class.isAssignableFrom(klass);
	}

	public void validate(Object target, Errors errors, String password) {
		ChangePassword changePassword = (ChangePassword) target;
		
		
		if (!(changePassword.getOldPassword()).equals(password)) {
			errors.rejectValue("oldPassword",
					"matchingPassword.changePassword.oldPassword",
					"Old Password is incorrect.");
		}
		
		
		if (!(changePassword.getNewPassword()).equals(changePassword.getConfirmPassword())) {
			errors.rejectValue("newPassword",
					"matchingPassword.changePassword.newPassword",
					"New Password and Confirm Password Not match.");
		}
	}
}
